﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PhoneBilling.Models
{
    [Serializable]
    public class MenuModel
    {
        public List<Menu> TopMenuList { get; set; }
        public Menu SelectedTopMenu { get; set; }

        public Menu SelectedLeftMenu { get; set; }

        public void Load()
        {
            TopMenuList = new List<Menu>() 
            {
                new Menu(){ Title = "基础管理" , Key = "Manage" , SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "部组管理" , Key = "Manage/DepartmentMgt"},
                    new Menu(){ Title = "分机查询" , Key = "Manage/ExtensionSearch"},
                    new Menu(){ Title = "费率表维护" , Key = "Manage/TraiffMgt"},
                    new Menu(){ Title = "费率管理" , Key = "Manage/Traiff"},
                    new Menu(){ Title = "优惠表管理" , Key = "Manage/DiscountMgt"},
                    new Menu(){ Title = "分段计费表维护" , Key = "Manage/SliceMgt"},
                    new Menu(){ Title = "分段计费管理" , Key = "Manage/SliceDetailMgt"},
                    new Menu(){ Title = "收费等级维护" , Key = "Manage/GradesMgt"},
                    new Menu(){ Title = "收费等级管理" , Key = "Manage/GradeDetailMgt"},
                    new Menu(){ Title = "用户管理" , Key = "Manage/UserMgt"},
                }},
                new Menu(){ Title = "收款结账" , Key = "Billing", SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "结账" , Key = "Billing/Account"},
                    new Menu(){ Title = "部组收款" , Key = "Billing/GroupPayment"},
                    new Menu(){ Title = "分机收款" , Key = "Billing/PhonePayment"},
                }},
                new Menu(){ Title = "查询统计" , Key = "Statistics", SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "待结账统计" , Key = "Statistics/Report1"},
                    new Menu(){ Title = "账目统计" , Key = "Statistics/Report2"},
                    new Menu(){ Title = "部门话务统计" , Key = "Statistics/Report4"},
                    new Menu(){ Title = "分组话务统计" , Key = "Statistics/Report9"},
                    new Menu(){ Title = "分机话务统计" , Key = "Statistics/Report3"},
                    new Menu(){ Title = "日话务统计" , Key = "Statistics/Report5"},
                    //new Menu(){ Title = "收费等级统计" , Key = "Statistics/Report6"},
                    new Menu(){ Title = "话务状况统计" , Key = "Statistics/Report7"},
                    new Menu(){ Title = "长途统计" , Key = "Statistics/Report8"},
                }},
                new Menu(){ Title = "系统维护" , Key = "System", SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "不明话单管理" , Key = "System/Unkown"},
                    new Menu(){ Title = "原始话单查询" , Key = "System/SourcePhn"},
                }},
            };
        }

        public void SetMenu(string topMenuKey, string leftMenuKey)
        {
            SelectedTopMenu = null;
            SelectedLeftMenu = null;

            foreach (var topMenu in TopMenuList)
            {
                if (topMenu.Key == topMenuKey)
                    SelectedTopMenu = topMenu;

                if(topMenu.SubMenu == null)
                    continue;
                foreach(var leftMenu in topMenu.SubMenu)
                    if (leftMenu.Key == leftMenuKey)
                        SelectedLeftMenu = leftMenu;
            }

            if (SelectedTopMenu == null)
            {
                SelectedTopMenu = new Menu() { Key = string.Empty, Title = string.Empty };            
            }
        }

        public void SetMenu(string topMenuKey)
        {
            SelectedTopMenu = null;
            SelectedLeftMenu = null;

            foreach (var topMenu in TopMenuList)
            {
                if (topMenu.Key == topMenuKey)
                    SelectedTopMenu = topMenu;
            }

            if (SelectedTopMenu == null)
            {
                SelectedTopMenu = new Menu() { Key = string.Empty, Title = string.Empty };
            }
        }
    }


}